const corsMiddle = (req, res, next) => {
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Headers", "Content-Type, Authorization");
    res.header("Access-Control-Allow-Methods", "PUT, POST, GET, DELETE, OPTIONS");
    res.header("Access-Control-Allow-Credentials", "true");
    
    // 处理预检请求
    if (req.method === "OPTIONS") {
        res.sendStatus(200);
        return;
    }
    
    next(); // 放行
}

module.exports = corsMiddle;